package com.example.servicemail.scheduler;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class TestScheduler {

    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Scheduled(fixedDelay = 5000)
    public void testJob() {
        System.out.println("每5秒执行一次" + sdf.format(new Date()));
    }

    @Scheduled(fixedRate = 2000)
    public void testFixedRateJob() {
        System.out.println("每2秒执行一次" + sdf.format(new Date()));
    }

    @Scheduled(cron = "0 * * * * ?")
    public void sendMailJob() {

        System.out.println("每个整分钟执行一次" + sdf.format(new Date()));
    }

}
